package 算法shiyan.shiayn3;

import java.util.Scanner;

/**
/**
 * @ProjectName: projectweb
 * @ClassName: 汉诺塔问题
 * @Author: 1913040634刘世锦
 * @Date: 2021/4/15 20:06 .
 * @version v1.0
 */
public class 汉诺塔问题 {
static  int m = 0;
     public static   void move (int n,String a,String c ){

         System.out.println("第"+(++m)+"此移动"+"把第-"+ n +"-个金盘从_"+ a +"_移到"+ c);

     }
     public static void hannuota(int n,String a,String b ,String c){
         if(n==1){
             move(1,a,c);
         }else{
             hannuota(n-1,a,c,b);
             move(n,a,c);
             hannuota(n-1,b,a,c);

         }
     }

    public static void main(String[] args) {
        String a = "A";
        String b = "B";
        String c = "C";
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入金盘个数：");
        int n = sc.nextInt();
        hannuota(n,a,b,c);
        System.out.println("共移动"+m+"次");
    }

}
